package com.bingxue.edu.framework.storage;

import com.bingxue.edu.common.enums.CommonStatusEnum;
import com.bingxue.edu.management.system.model.entity.Storage;
import com.bingxue.edu.management.system.model.query.StorageQuery;
import com.bingxue.edu.management.system.service.StorageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.bingxue.edu.management.system.model.entity.table.StorageTableDef.STORAGE;

/**
 * 文件存储配置加载器
 *
 * @author panbo
 * @since 2024/07/24
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class FileStorageConfigLoader implements ApplicationRunner {

    private final StorageService storageService;

    @Override
    public void run(ApplicationArguments args) {
        StorageQuery query = new StorageQuery();
        query.setStatus(CommonStatusEnum.ENABLED);
        List<Storage> storageList = storageService.queryChain().where(STORAGE.STATUS.eq(CommonStatusEnum.ENABLED)).list();
        storageList.forEach(storageService::load);
        log.info("加载存储成功");
    }
}
